////////////////////////////////////////////////////////////////////////////////////
// File:        EsetInfo.h
// Purpose:     Class which stores the Eset Information (version, version type, 
//              language and state
// Author:      Tukero
// Copyright:   (c) Tukero <tukero@gmail.com>
// Licence:     GNU/LGPL v3
////////////////////////////////////////////////////////////////////////////////////

#ifndef _TNOD_ESETINFO_
#define _TNOD_ESETINFO_

#ifndef WX_PRECOMP
#  include <wx/wx.h>
#else
#  include <wx/wxprec.h>
#endif

//
// To store the version
//
class EsetVersion
{
public:
    long m_Major;
    long m_Minor;
    long m_Release;
    long m_Build;
    EsetVersion( long major, long minor, long release, long build )
    {
        m_Major = major;
        m_Minor = minor;
        m_Release = release;
        m_Build = build;
    }
    EsetVersion()
    {
        m_Major = 0;
        m_Minor = 0;
        m_Release = 0;
        m_Build = 0;
    }
    void CopyTo( EsetVersion& destiny )
    {
        destiny.m_Build = m_Build;
        destiny.m_Major = m_Major;
        destiny.m_Release = m_Release;
        destiny.m_Minor = m_Minor;
    }

    //Separates the version
    void SetFromConversion(long build)
    {
        if (build >= 0x10000000) build -= 0x10000000;
        if (build >=  0x1000000) build -=  0x1000000;

        m_Major=(long)build / 0x3E800;
        build %= 0x3E800;

        m_Minor=(long)build / 256;
        build %= 256;

        m_Release=(long)build;
        m_Build=0;
    }
    wxString GetInStringFormat()
    {
        wxString StrVersion;
        StrVersion.Printf(wxT("%li.%li.%li.%li"),m_Major,m_Minor,m_Release,m_Build);
        return StrVersion;
    }
};

class EsetInfo
{    
protected:
    EsetVersion m_EsetVersion;
    wxString    m_VersionType;                            //Version type (ess, essbe, eav, eavbe)
    long        m_LanguageId;
    int         m_NodState;                               //NOD32 state
    
public:
    //
    // To know the NOD32 state
    //
    enum 
    {
        NOD_ISNOTINSTALLED,
        NOD_OLDVERSION,
        NOD_NEWVERSION
    };
    EsetInfo(EsetVersion& nodVersion, int NodState = NOD_ISNOTINSTALLED, wxString versionType = wxT("eav"), long languageId = 0x409)
    {
        m_NodState = NodState;

        nodVersion.CopyTo( m_EsetVersion );
        m_VersionType = versionType;
        m_LanguageId = languageId;
    }
    EsetInfo()
    {
        //fills the data with the default nod32 antivirus
        m_EsetVersion.m_Major = 4;
        m_EsetVersion.m_Minor = 0;
        m_EsetVersion.m_Release = 474;
        m_EsetVersion.m_Build = 0;
        m_VersionType = wxT("eav");
        m_LanguageId = 0x409;        
        m_NodState = NOD_ISNOTINSTALLED;
    }
    long    GetMajorVersion() const { return m_EsetVersion.m_Major; }


    // Return the NOD32 type installed ("ess" -Eset Smart Security-, "eav" -Eset NOD32 Antivirus-, "eavbe" -Eset NOD32 Antivirus Antivirus Bussiness Edition, "essbe" -Eset Smart Security Bussiness Edition)
    wxString GetVersionType() const { return m_VersionType; } 

    long     GetLanguageId() const { return m_LanguageId; }

    // Return the NOD32 version in #.#.# format
    wxString GetStrVersion() {  return m_EsetVersion.GetInStringFormat(); }

    // Return the NOD32 installation state
    int     GetNodState() const { return m_NodState; }

    // Return the NOD32 version
    void    GetNodVersion(EsetVersion &NodVersion)
    {
        m_EsetVersion.CopyTo( NodVersion );
    }
    
    void    SetVersionType(wxString versionType)
    {
        m_VersionType = versionType;
    }
};

#endif